/*****************************************************************//**
 * \file   TxtMemStream.cpp
 * \brief  TxtMemStream
 * 
 * \author Wyatt
 * \date   May 2023
 *********************************************************************/
#include "TxtMemStream.h"

using std::string;
TxtMemStream::TxtMemStream(string filePath)
	: _filePath(filePath)
{
	_fs.open(_filePath, std::ios::in);
}

TxtMemStream::~TxtMemStream()
{
	if (is_open())
		close();
}

bool TxtMemStream::is_open()
{
	return _fs.is_open();
}

void TxtMemStream::close()
{
	_fs.close();
}

std::istream& TxtMemStream::getline(std::string& buff)
{
	nLine++;
	return std::getline(_fs, buff);
}

void TxtMemStream::seekg(long long off, PosType way)
{
	if (PosBegin == way)
	{
		nLine = 0;
		_fs.clear();
		_fs.seekg(off, std::ios::beg);
	}
	else if (PosEnd == way)
	{
		nLine = -1;
		_fs.clear();
		_fs.seekg(off, std::ios::end);
	}
}
